# Maintainer: Andrew Leech <andrew@alelec.net>
# Contributor: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Rocco Marco Guglielmi <guglielmir@playembedded.org>

_realname=openocd
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.10.0.r870.gaf952850b
pkgrel=1
pkgdesc="OpenOCD - Open On-Chip Debugger (mingw-w64)"
arch=('any')
url="http://openocd.org/"
license=("GPLv2")
options=('!ccache')
depends=("${MINGW_PACKAGE_PREFIX}-hidapi"
         "${MINGW_PACKAGE_PREFIX}-libusb"
         "${MINGW_PACKAGE_PREFIX}-libusb-compat"
         "${MINGW_PACKAGE_PREFIX}-libftdi"
         "${MINGW_PACKAGE_PREFIX}-libjaylink")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "git")
source=("${_realname}::git+https://git.code.sf.net/p/openocd/code")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}"/${_realname}
  git describe --long --tags 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "${srcdir}"/${_realname}
  ./bootstrap
}

build() {
  cd "${srcdir}"/${_realname}

  ./configure \
      --prefix=${MINGW_PREFIX} \
      --{build,host}=${MINGW_CHOST} \
      --disable-dependency-tracking \
      --disable-werror \
      --disable-internal-libjaylink \
      --enable-dummy \
      --enable-jtag_vpi \
      --enable-remote-bitbang \
      --enable-amtjtagaccel \
      --enable-gw16012 \
      --enable-parport \
      --enable-parport-giveio

  make
}

package() {
  cd "${srcdir}"/${_realname}
  make DESTDIR="${pkgdir}" install
  install -Dm644 COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING

  # bsdtar can't convert non-ascii filenames to UTF-8 when run in
  # non-UTF-8 locale. It proceeds to pack them anyway embedding raw
  # binary filenames in the traditional tar headers.
}
